//
//  MyEmptyView.m
//
//  Copyright © 2019 Dean. All rights reserved.
//

#import "MyEmptyView.h"

@implementation MyEmptyView
+ (MyEmptyView *)emptyWithContentViewDetailStr:(NSString*)detailStri
                                      imageStr:(NSString*)imageStr
                                     btnString:(NSString *)btnString
                                 btnClickBlock:(LYActionTapBlock)btnClickBlock
                                 configerBlock:(void (^)(MyEmptyView *configer))configerBlock {
    
    MyEmptyView *diy = [MyEmptyView emptyActionViewWithImageStr:imageStr titleStr:nil detailStr:detailStri btnTitleStr:btnString btnClickBlock:btnClickBlock];
    diy.subViewMargin = RatioHeight(30);
    diy.actionBtnMargin = RatioHeight(72);
    if (configerBlock) {
        configerBlock(diy);
    }
        return diy;
}
/// 纯文字 没有默认图片
+ (MyEmptyView *)emptyWithContentViewDetailStr:(NSString*)detailStri
                                 configerBlock:(void (^)(MyEmptyView *configer))configerBlock {
    MyEmptyView *diy = [MyEmptyView emptyActionViewWithImageStr:@"CantUseEmptyImage" titleStr:nil detailStr:detailStri btnTitleStr:nil btnClickBlock:nil];
    if (configerBlock) {
        configerBlock(diy);
    }
    return diy;
    
}
+ (MyEmptyView *)emptyWithContentViewDetailStr:(NSString*)detailStri
                                      imageStr:(NSString*)imageStr
                                 btnClickBlock:(LYActionTapBlock)btnClickBlock
                                 configerBlock:(void (^)(MyEmptyView *configer))configerBlock;{
    
    MyEmptyView *diy = [MyEmptyView emptyActionViewWithImageStr:imageStr titleStr:nil detailStr:detailStri btnTitleStr:@"添加" btnClickBlock:btnClickBlock];
    diy.subViewMargin = RatioHeight(20);
    diy.actionBtnMargin = RatioHeight(72);
    diy.actionBtnHeight = RatioWidth(30);
    diy.actionBtnCornerRadius = 4;
    if (configerBlock) {
        configerBlock(diy);
    }
    return diy;
}

+ (MyEmptyView *)emptyWithContentView:(UIScrollView *)contentView
                                title:(NSString*)title
                             imageStr:(NSString*)imageStr
                        configerBlock:(void (^)(MyEmptyView *configer))configerBlock{
    MyEmptyView *diy = [MyEmptyView emptyViewWithImageStr:imageStr
                                                 titleStr:nil
                                                detailStr:title];
    

    diy.contentViewOffset = -RatioHeight(80);
    contentView.ly_emptyView = diy;
    if (configerBlock) {
        configerBlock(diy);
    }
    return diy;
    
}

+ (instancetype)diyNoDataOrderEmptyDetail:(NSString*)detail imageStr:(NSString*)imageStr {
    
      MyEmptyView *diy = [MyEmptyView emptyViewWithImageStr:imageStr
                                                   titleStr:nil
                                                  detailStr:detail];
      
      diy.contentViewOffset = -RatioHeight(80);
      return diy;
    
}
+ (instancetype)diyNoDataOrderEmptyDetail:(NSString*)detail{
    
    return [self diyNoDataOrderEmptyDetail:detail imageStr:@"empty_nodata"];

}
+ (instancetype)diyNoDataOrderEmpty{
    return [self diyNoDataOrderEmptyDetail:@"您还没有相关订单"];
}

+ (instancetype)diyNoDataNetWorkEmpty{
    return [MyEmptyView emptyViewWithImageStr:@"empty_nodata"
                                    titleStr:@"暂无数据"
                                   detailStr:@"请检查您的网络连接是否正确!"];
}
+ (instancetype)diyNoNetworkEmptyWithTarget:(id)target action:(SEL)action{
    
    MyEmptyView *diy = [MyEmptyView emptyActionViewWithImageStr:@"empty_nodata"
                                                     titleStr:nil
                                                    detailStr:@"请检查你的网络连接是否正确!"
                                                  btnTitleStr:@"重新加载"
                                                       target:target
                                                       action:action];
    diy.autoShowEmptyView = NO;
    diy.emptyViewIsCompleteCoverSuperView = YES;
    diy.backgroundColor = UIColorForBackground;
//    diy.imageSize = CGSizeMake(150, 150);
    diy.size = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT);
    diy.contentViewOffset = -RatioHeight(80);

    return diy;
}

+ (instancetype)diyCustomEmptyViewWithTarget:(id)target action:(SEL)action{
    
    UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 80)];
    
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
    titleLab.font = [UIFont systemFontOfSize:16];
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.text = @"暂无数据，请稍后再试！";
    [customView addSubview:titleLab];
    
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 50, 80, 30)];
    button.backgroundColor = [UIColor blueColor];
    [button setTitle:@"重试" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [customView addSubview:button];
    
    UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(120, 50, 80, 30)];
    button2.backgroundColor = [UIColor redColor];
    [button2 setTitle:@"加载" forState:UIControlStateNormal];
    button2.titleLabel.font = [UIFont systemFontOfSize:15];
    [button2 addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [customView addSubview:button2];
    
    MyEmptyView *diy = [MyEmptyView emptyViewWithCustomView:customView];
    return diy;
}

+ (instancetype)diyCustomEmptyView:(NSString *)hint{
    UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 80)];
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
    titleLab.font = [UIFont systemFontOfSize:16];
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.text = hint;
    [customView addSubview:titleLab];

    MyEmptyView *diy = [MyEmptyView emptyViewWithCustomView:customView];
    return diy;
}

- (void)prepare{
    [super prepare];
    
    self.subViewMargin = 20.f;
    
    self.titleLabFont = TGAutoFont(17.0f);
    self.titleLabTextColor = DeepBlackColor;
    
    self.detailLabTextColor = RGBA(102, 102, 102, 1);
    self.detailLabMaxLines = 5;
    self.detailLabFont = TGAutoFont(14);
    self.actionBtnBackGroundColor = [UIColor clearColor];
    self.actionBtnTitleColor = RedColor;
    self.actionBtnFont = TGAutoFont(14);
    self.actionBtnBorderColor = RedColor;
    self.actionBtnBorderWidth = PixelOne;
    self.actionBtnHeight =  RatioHeight(24);
    self.actionBtnCornerRadius = RatioHeight(12);
    self.actionBtnHorizontalMargin =  RatioWidth(12);

}


@end
